package org.snail.admin.backend.dao;

import org.apache.ibatis.annotations.*;
import org.snail.admin.backend.entity.UserEntity;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("SELECT id, birthday, create_time, name, pay, password FROM sys_user WHERE id = #{id}")
    UserEntity findById(Long id);


    @Select("SELECT id, birthday, create_time, name, pay, password FROM sys_user")
    List<UserEntity> findAll();

    @Insert("INSERT INTO sys_user(birthday, create_time, name, pay, password) " +
            "VALUES(#{birthday}, #{createTime}, #{name}, #{pay}, #{password})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(UserEntity user);

    @Update("UPDATE sys_user SET birthday = #{birthday}, create_time = #{createTime}, " +
            "name = #{name}, pay = #{pay}, password = #{password} " +
            "WHERE id = #{id}")
    int update(UserEntity user);

    @Delete("DELETE FROM sys_user WHERE id = #{id}")
    int deleteById(Long id);

    @Select("SELECT id, birthday, create_time, name, pay, password FROM sys_user WHERE name = #{name}")
    UserEntity findByName(String name);
}